//
//  DSYSubTableViewCell.m
//  BLDMusics
//
//  Created by dllo on 16/3/18.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "DSYSubTableViewCell.h"
#import "DSYCarouselModel.h"

#define kDSYContentW self.contentView.frame.size.width
#define HOLDER [UIImage imageNamed:@"recommend_header_placeholder.jpg"]

@interface DSYSubTableViewCell ()

@property (nonatomic, retain) UIImageView *imgView;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *descLabel;

@end

@implementation DSYSubTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubviews];
    }
    return self;
}

- (void)creatSubviews {
    
    self.imgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_imgView];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    
    self.descLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_descLabel];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _imgView.frame = CGRectMake(10, 5, self.contentView.frame.size.height - 10, self.contentView.frame.size.height - 10);
    _nameLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame) + 10, CGRectGetMidY(_imgView.frame) - 30, kDSYContentW - CGRectGetMaxX(_imgView.frame) - 10, 30);
    _descLabel.frame = CGRectMake(CGRectGetMinX(_nameLabel.frame), CGRectGetMidY(_imgView.frame), CGRectGetWidth(_nameLabel.frame), CGRectGetHeight(_nameLabel.frame));
    
    _descLabel.font = [UIFont systemFontOfSize:15.0f];
    _descLabel.textColor = [UIColor lightGrayColor];
}

- (void)setSourceModel:(DSYCarouselModel *)sourceModel
{
    _sourceModel = sourceModel;
    [self updateUI];
}

- (void)updateUI {
    
    [_imgView sd_setImageWithURL:[NSURL URLWithString:_sourceModel.picUrl] placeholderImage:HOLDER];
    
    _nameLabel.text = _sourceModel.name;
    _descLabel.text = _sourceModel.desc;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
